<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('文件列表')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="easyfile-form">
					<div class="select-list">
						<ul>
							<li>
								文件名称：<input type="text" name="originalName" placeholder="请输入文件名称"/>
							</li>
							<li>
								文件状态：<select name="status" th:with="type=${@dict.getDict('sys_data_status')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.dictName}" th:value="${dict.dictValue}"></option>
								</select>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-default btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-primary" onclick="easyFileUpload()" shiro:hasPermission="easyfile:file:upload">
	                <i class="fa fa-cloud-upload"></i> 上传
	            </a>
				<a class="btn btn-primary single disabled" onclick="easyFileDownload()" shiro:hasPermission="easyfile:file:download">
		            <i class="fa fa-cloud-download"></i> 下载
		        </a>
				<a class="btn btn-primary multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="easyfile:file:remove">
		            <i class="fa fa-trash"></i> 删除
		        </a>
	        </div>
	        
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var prefix = ctx + "easyfile";

		$(function() {
		    var options = {
		        url: prefix + "/list",
		        removeUrl: prefix + "/remove",
		        sortName: "createTime",
		        sortOrder: "desc",
		        modalName: "文件",
		        columns: [{
		            checkbox: true
		        },
		        {
		            field: 'id',
		            visible: false
		        },
		        {
		            field: 'originalName',
		            title: '文件名称',
		            sortable: true,
		            formatter: function(value, row, index) {
                    	return $.table.tooltip(value);
                    }
		        },
		        {
		            field: 'fileSize',
		            title: '文件大小',
		            sortable: true,
		            formatter: function(value, row, index) {
                    	return fileFormatSize(value);
                    }
		        },
		        {
		            field: 'fileSuffix',
		            title: '文件后缀',
		            sortable: true
		        },
		        {
		            field: 'fileType',
		            title: '文件类型',
		            sortable: true,
		            formatter: function(value, row, index) {
                    	return $.table.tooltip(value);
                    }
		        },
		        {
		            field: 'status',
		            title: '文件状态',
		            sortable: true
		        },
		        {
		            field: 'createBy',
		            title: '创建人',
		            sortable: true
		        },
		        {
		            field: 'createTime',
		            title: '创建时间',
		            sortable: true
		        },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	return $('#operateTpl').tmpl(row).html();
		            }
		        }]
		    };
		    $.table.init(options);
		});
		
		//上传
		function easyFileUpload(){
			$.modal.openOptions({
				title: "上传文件",
				url: prefix + "/upload/general",
				yes: function(index, layero){
					var iframeWin = layero.find('iframe')[0];
                    var data = iframeWin.contentWindow.Easyfile.results;//获取上传成功后的文件信息
                    console.info(data);
					$.table.refresh();
					layer.close(index);
				}
			});
		}
		//下载
		function easyFileDownload(id){
			if($.common.isEmpty(id)){
				var rows = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
	       		if (rows.length == 0) {
	       			$.modal.alertWarning("请至少选择一条记录");
	       			return;
	       		}
	       		id = rows[0];
			}
			window.open(prefix + '/download/' + id);
		}
	</script>
</body>
<!-- 表格操作列 -->
<script id="operateTpl" type="text/template">
<tmpl>
	<a href="javascript:easyFileDownload('${id}')" shiro:hasPermission="easyfile:file:download" class="btn btn-primary btn-xs">
		<i class="fa fa-cloud-download"></i> 下载
	</a>
	<a href="javascript:$.operate.remove('${id}')" shiro:hasPermission="easyfile:file:remove" class="btn btn-danger btn-xs">
		<i class="fa fa-trash"></i> 删除
	</a> 
</tmpl>
</script>
</html>